package com.xrit.sunnyday.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.xrit.sunnyday.dao.MemberDao;
import com.xrit.sunnyday.dao.OrderDao;
import com.xrit.sunnyday.service.ReportService;
import com.xrit.sunnyday.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Service(interfaceClass = ReportService.class)
public class ReportServiceImpl  implements ReportService {

    @Autowired
    private MemberDao memberDao;

    @Autowired
    private OrderDao orderDao;
    @Override
    public Map<String, Object> getBusinessReport() {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        //reportDate,今天
        String today = sdf.format(new Date());
        //周一
        String monday = sdf.format(DateUtils.getThisWeekMonday());
        //周日
        String sunday = sdf.format(DateUtils.getSundayOfThisWeek());
        //1号
        String firstDayOfThisMonth = sdf.format(DateUtils.getFirstDay4ThisMonth());
        //本月的最后一天
        String lastDayOfThisMonth = sdf.format(DateUtils.getLastDayOfThisMonth());

        //===============会员统计===================
        //todayNewMember
        Integer todayNewMember = memberDao.findMemberCountByDate(today);
        //totalMember
        Integer totalMember = memberDao.findMemberTotalCount();
        // thisWeekNewMember
        Integer thisWeekNewMember = memberDao.findMemberCountAfterDate(monday);
        //thisMonthNewMember
        Integer thisMonthNewMember = memberDao.findMemberCountAfterDate(firstDayOfThisMonth);

        //===============预约统计===================
        //todayOrderNumber
        Integer todayOrderNumber = orderDao.findOrderCountByDate(today);
        //todayVisitsNumber:今日到诊数
        Integer todayVisitsNumber = orderDao.findVisitsCountByDate(today);
        //thisWeekOrderNumber
        Integer thisWeekOrderNumber =orderDao.findOrderCountBetweenDate(monday,sunday);
        //thisWeekVisitsNumber
        Integer thisWeekVisitsNumber = orderDao.findVisitsCountAfterDate(monday);
        //thisMonthOrderNumber
        Integer thisMonthOrderNumber =orderDao.findOrderCountBetweenDate(firstDayOfThisMonth,lastDayOfThisMonth);
        //thisMonthVisitsNumber
        Integer thisMonthVisitsNumber = orderDao.findVisitsCountAfterDate(firstDayOfThisMonth);

        //===============热门套餐===================
        List<Map<String,Object>> hotSetmeal = orderDao.findHotSetmeal();

        //===============返回前端页面需要的Map===================
        Map<String,Object> map = new HashMap<>();
        map.put("reportDate",today);
        map.put("todayNewMember",todayNewMember);
        map.put("totalMember",totalMember);
        map.put("thisWeekNewMember",thisWeekNewMember);
        map.put("thisMonthNewMember",thisMonthNewMember);

        map.put("todayOrderNumber",todayOrderNumber);
        map.put("todayVisitsNumber",todayVisitsNumber);
        map.put("thisWeekOrderNumber",thisWeekOrderNumber);
        map.put("thisWeekVisitsNumber",thisWeekVisitsNumber);
        map.put("thisMonthOrderNumber",thisMonthOrderNumber);
        map.put("thisMonthVisitsNumber",thisMonthVisitsNumber);

        map.put("hotSetmeal",hotSetmeal);
        return map;
    }
}
